home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 May / CMCD0505.ISO / Software / Demo / DesktopX / objects / ktekdockv1.dxpack / {50B76F56-7339-4DB8-B1B9-3CC5E35EA52D}.DXScript2 < prev    next >
Extensible Markup Language  |  2004-08-24  |  4KB  |  168 lines

  1. <?xml version="1.0"?>
  2. <!--DXScript Data File.  Version 2.0-->
  3. <DXScript>
  4.     <Script><![CDATA[Dim decimal'whether or not a decimal point is part of the number
  5. Dim operator'the currently active operator that will be applied to a calculation
  6. Dim operand'the number that will be operated on by the displayed number
  7. Dim operand2
  8. Dim newoperand'whether to create a new number in the display if digits pressed
  9. Dim newsum'whether a result has been calculated
  10. Dim lastinputtype'operator or numerical
  11. 'Called when the script is executed
  12. Sub Object_OnScriptEnter
  13.     decimal=0
  14.     operator="="
  15.     operand="0"
  16.     newoperand=False
  17.     newsum=True
  18.     lastinputtype="numeric"
  19.     desktopx.Object("kdockcalcop").text="[=]"
  20.     desktopx.Object("kdockcalcreadout").text="0"
  21. End Sub
  22.  
  23. Sub calculate(k)
  24.     t=desktopx.Object("kdockcalcreadout").text
  25.     If instr(t,".")=False Then decimal=0
  26.     If (isnumeric(k) Or k="point" Or k="backspace") And newoperand Then
  27.         t="0"
  28.         newoperand=False
  29.         lastinputtype="numeric"
  30.     End If
  31.     If t="E" Then
  32.         t="0"
  33.         newoperand=False
  34.         lastinputtype="numeric"
  35.         desktopx.Object("kdockcalcreadout").text=t
  36.     End If
  37.     
  38.     If k="" Then
  39.         Exit Sub
  40.     ElseIf k="esc" Then'reset everything for a new beginning!
  41.         decimal=0
  42.         operator="="
  43.         operand="0"
  44.         newoperand=False
  45.         newsum=True
  46.         lastinputtype="numeric"
  47.         desktopx.Object("kdockcalcop").text="[=]"
  48.         t="0"
  49.     ElseIf k="backspace" Then
  50.         If len(t)>1 Then
  51.             t=left(t,len(t)-1)
  52.         Else
  53.             t="0"
  54.             newoperand=False
  55.         End If
  56.     ElseIf k="point" Then
  57.         If decimal=1 Or len(t)>9+decimal Then Exit Sub
  58.         t=t&"."
  59.         decimal=1
  60.     ElseIf isnumeric(k) Then
  61.         If len(t)>9+decimal Then Exit Sub
  62.         lastinputtype="numeric"
  63.         If t="0" Then
  64.             t=Cstr(k)
  65.         Else    
  66.             t=t&Cstr(k)
  67.         End If
  68.     Else'if k is one of the operator keys
  69.         operate(k)
  70.         Exit Sub
  71.     End If
  72.     desktopx.Object("kdockcalcreadout").text=t
  73. End Sub
  74.  
  75. Sub operate(o)
  76.     t=Cdbl(desktopx.Object("kdockcalcreadout").text)
  77.     If o="enter" Then
  78.         If operator<>"=" And operand<>"" Then 
  79.             dothesum
  80.             newsum=True
  81.             newoperand=True
  82.             operator="="
  83.             desktopx.Object("kdockcalcop").text="["&operator&"]"
  84.         End If
  85.         Exit Sub
  86.     Else
  87.         'desktopx.Object("temp").text="newoperand="&newoperand _
  88.         '&Chr(13)&"operand="&operand _
  89.         '&Chr(13)&"newsum="&newsum _
  90.         '&Chr(13)&"lastinputtype="&lastinputtype
  91.         If lastinputtype<>"operator" And newsum=False Then 
  92.             dothesum    
  93.         Else
  94.             operand=t
  95.             newsum=False
  96.         End If
  97.         If o="plus" Then
  98.             operator="+"
  99.         ElseIf o="minus" Then
  100.             operator="-"    
  101.         ElseIf o="times" Then
  102.             operator="*"
  103.         ElseIf o="divide" Then
  104.             operator="/"
  105.         End If
  106.     End If        
  107.     newoperand=True
  108.     lastinputtype="operator"
  109.     If operator="*" Then
  110.         desktopx.Object("kdockcalcop").text="[x]"
  111.     Else
  112.         desktopx.Object("kdockcalcop").text="["&operator&"]"
  113.     End If
  114. End Sub
  115.  
  116. Sub dothesum
  117.     t=Cdbl(desktopx.Object("kdockcalcreadout").text)
  118.     If operator="+" Then
  119.         result=operand+t
  120.     ElseIf operator="-" Then
  121.         result=operand-t    
  122.     ElseIf operator="*" Then
  123.         result=operand*t
  124.     ElseIf operator="/" Then
  125.         If t=0 Then 
  126.             result="E"
  127.         Else
  128.             result=operand/t
  129.         End If
  130.     End If
  131.     desktopx.Object("kdockcalcreadout").text=result
  132.     operand=result
  133. End Sub
  134.  
  135.  
  136. Function Object_OnChar(key, extended)
  137.     Select Case key
  138.         Case 48 k=0
  139.         Case 49 k=1
  140.         Case 50 k=2
  141.         Case 51 k=3
  142.         Case 52 k=4
  143.         Case 53 k=5
  144.         Case 54 k=6
  145.         Case 55 k=7
  146.         Case 56 k=8
  147.         Case 57 k=9    
  148.         Case 13 k="enter"
  149.         Case 27 k="esc"
  150.         Case 46 k="point"
  151.         Case 42 
  152.             k="times"
  153.         Case 43 
  154.             k="plus"
  155.         Case 45 
  156.             k="minus"
  157.         Case 47 
  158.             k="divide"
  159.         Case 8 k="backspace"        
  160.         Case Else k=""
  161.     End Select
  162.     'desktopx.Object("kdockcalcop").text=key
  163.     calculate(k)
  164.     Object_OnChar = False
  165. End Function
  166.  
  167. ]]></Script><Globals><Editor><PropPane>0</PropPane><EditorLeft>270</EditorLeft><EditorTop>72</EditorTop><EditorRight>1048</EditorRight><EditorBottom>843</EditorBottom></Editor><Object><LanguageCLSID>{B54F3741-5B07-11CF-A4B0-00AA004A55E8}</LanguageCLSID><ControlCLSID>{00000000-0000-0000-0000-000000000000}</ControlCLSID><ControlObjWidth>64</ControlObjWidth><ControlObjHeight>64</ControlObjHeight><RunState>1</RunState><ManualControlLoad>0</ManualControlLoad><ScriptHostVersion>2</ScriptHostVersion></Object></Globals></DXScript>
  168.